﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Utils;

namespace WCS.Entity
{
    [SugarTable("WCS_WarehouseIO")]
    public class WarehouseIO
    {
        /// <summary>
        /// 仓库ID
        /// </summary>
        public string ID { get; set; }

        /// <summary>
        /// 托盘序号
        /// </summary>
        public int index { get; set; }

        /// <summary>
        /// 托盘号
        /// </summary>
        public string barCode { get; set; }

        /// <summary>
        /// 托盘1的数据内容
        /// </summary>
        public string BarCodeData { get; set; }

        /// <summary>
        /// 库存状态
        /// </summary>
        public int state { get; set; }

        /// <summary>
        /// 库存状态
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 仓库号
        /// </summary>
        public string WarehouseCode { get; set; }

        public string Task_type { get; set; }

        [SugarColumn(IsIgnore = true)]
        public int Qty { get; set; }

        /// <summary>
        /// 数据库连接对象
        /// </summary>
        static SqlSugarDapper _SqlSugarDapper = SqlSugarDapper.GetDbContext();

        public static void AddWarehouseInfo(WarehouseIO warehouseIO)
        {
            _SqlSugarDapper.DB.Insertable(warehouseIO).ExecuteCommand();
            DeleteWarehouseInfo();
        }

        /// <summary>
        /// 删除10天前的记录
        /// </summary>
        /// <param name="warehouseIO"></param>
        public static void DeleteWarehouseInfo()
        {
            _SqlSugarDapper.DB.Deleteable<WarehouseIO>().Where(w => w.CreateTime < DateTime.Now.AddDays(-7)).ExecuteCommand();
        }
    }
}
